package com.aglow.hyyff;

import android.Manifest;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.aglow.eventbus.bean.Event;
import com.aglow.eventbus.until.EventUntils;
import com.aglow.hyyff.base.BaseActivity;
import com.aglow.hyyff.bean.EventTest;
import com.aglow.updateDownload.code.DownloadManager;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.XXPermissions;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Author: chufeng
 * Email: 392044178@qq.com
 * Date: 2019/1/2 11:23
 * Depict:
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private String TAG = "main";
    private Button eventButtom;
    private Button downloadButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getPremissions();

        eventButtom = findViewById(R.id.evets);
        downloadButton = findViewById(R.id.downloader);
        eventButtom.setOnClickListener(this);
        downloadButton.setOnClickListener(this);


    }

    /**
     * 动态申请权限
     **/
    public void getPremissions() {

        XXPermissions.with(this).permission(Manifest.permission.INTERNET,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE).request(new OnPermission() {
            @Override
            public void hasPermission(List<String> list, boolean b) {

            }

            @Override
            public void noPermission(List<String> list, boolean b) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.evets:
                Intent intent = new Intent(MainActivity.this, EventTestActivity.class);
                EventUntils.postSticky(new Event<>(new EventTest("666")));
                startActivity(intent);
                break;

            case R.id.downloader:
                Intent intent2 = new Intent(MainActivity.this, DownloadTestActivity.class);
                startActivity(intent2);
                break;

        }
    }
}
